<?php
require_once 'DBConnecter.inc';
class Vehicle extends DBConnecter {
	public $car_id = "";
	public $car_no = "";
	public $product_id = "";
	public $car_sosok = "";
	public $soyu_tp = "";
	public $license_plate = "";
	// public $made_in_y;
	// public $made_in_m;
	public $loop_tp = "";
	public $cur_d = "";
	// public $befo_d;
	// public $driver_chg_dt;
	public $mng_amt = "";
	public $org_amt = "";
	public $gps_amt = "";
	function __construct() {
		$this->connectDB ();
		// $this->selectDB ( 'devdog' );
	}
	public function tablePrint() {
		echo "<tr onclick=\"location.href='./vehicle_detail.php?pageType=2&id=" . $this->car_id . "'\">";
		
		echo "<td>" . $this->car_id . "</td>";
		echo "<td>" . $this->car_no . "</td>";
		echo "<td>" . $this->product_id . "</td>";
		echo "<td>" . $this->car_sosok . "</td>";
// 		echo "<td>" . $this->soyu_tp . "</td>";
// 		echo "<td>" . $this->cusm_cd . "</td>";
// 		echo "<td>" . $this->brno . "</td>";
		echo "<td>" . $this->license_plate . "</td>";
		// echo "<td>" . $this->made_in_y . "</td>";
		// echo "<td>" . $this->made_in_m . "</td>";
		echo "<td>" . $this->loop_tp . "</td>";
		echo "<td>" . $this->cur_d . "</td>";
		// echo "<td>" . $this->befo_d . "</td>";
		// echo "<td>" . $this->driver_chg_dt . "</td>";
		echo "</tr>";
	}
	public function search4table($table, $category, $value) {
		$sql = "CALL ".self::CONST_DB.".search('" . $table . "','" . $category . "','" . $value . "','','');select @out_err_cd, @out_err_msg;";
		$retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					$this->car_id = $row ['0'];
					$this->car_no = $row ['1'];
					$this->product_id = $row ['2'];
					$this->car_sosok = $row ['3'];
					$this->soyu_tp = $row ['4'];
					$this->cusm_cd = $row ['5'];
					$this->brno = $row ['6'];
					$this->license_plate = $row ['7'];
					// $this->made_in_y = $row ['8'];
					// $this->made_in_m = $row ['0'];
					$this->loop_tp = $row ['10'];
					$this->cur_d = $row ['11'];
					// $this->befo_d = $row ['12'];
					// $this->driver_chg_dt = $row ['13'];
					$this->mng_amt = $row ['14'];
					$this->org_amt = $row ['15'];
					$this->gps_amt = $row ['16'];
					
					// $retval [] = $article;
					$this->tablePrint ();
				}
				$rs->free ();
			}
			// if ($this->getMySqlConneter ()->more_results ()) {
			// if ($this->getMySqlConneter ()->next_result ()) {
			// $rs = $this->getMySqlConneter ()->store_result ();
			// if ($rs != null) {
			// $err_param = $rs->fetch_row ();
			// echo "[" . $err_param [0] . "]";
			// echo "[" . $err_param [1] . "]";
			// }
			// }
			// }
			// $this->getMySqlConneter ()->next_result ();
			// if ($this->getMySqlConneter ()->more_results ()) {
			// if ($this->getMySqlConneter ()->next_result ()) {
			// $rs = $this->getMySqlConneter ()->store_result ();
			// if ($rs != null) {
			// $err_param2 = $rs->fetch_row ();
			// echo "[" . $err_param2 [0] . "]";
			// echo "[" . $err_param2 [1] . "]";
			// }
			// }
			// }
		}
		// return $retval;
	}
	public function search4Detail($value) {
		$sql = "CALL ".self::CONST_DB.".search('6','1','" . $value . "', '', '');select @out_err_cd, @out_err_msg;";
		$retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					$this->car_id = $row ['0'];
					$this->car_no = $row ['1'];
					$this->product_id = $row ['2'];
					$this->car_sosok = $row ['3'];
					$this->license_plate = $row ['4'];
					$this->made_in_y = $row ['5'];
					$this->made_in_m = $row ['6'];
					$this->loop_tp = $row ['7'];
					$this->cur_d = $row ['8'];
					$this->befo_d = $row ['9'];
					$this->driver_chg_dt = $row ['10'];
				}
				$rs->free ();
			}
		}
	}

	public function createVehicle($car_no, $product_id, $car_sosok, $license_plate, $made_in_y, $made_in_m, $loop_tp, $cur_d, $befo_d, $driver_chg_dt) {
		$sql = "CALL ".self::CONST_DB.".car_insert('" . $car_no . "','" . $product_id . "','" . $car_sosok . "','" . $license_plate . "','" . $made_in_y . "','" . $made_in_m . "','" . $loop_tp . "','" . $cur_d . "','" . $befo_d . "','" . $driver_chg_dt . "');select @out_err_cd, @out_err_msg;";
		//echo $sql;
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}

	public function modifyVehicle($car_id, $car_no, $product_id, $car_sosok, $license_plate, $made_in_y, $made_in_m, $loop_tp, $cur_d, $befo_d, $driver_chg_dt) {
		$sql = "CALL ".self::CONST_DB.".car_update('" . $car_id . "','" . $car_no . "','" . $product_id . "','" . $car_sosok . "','" . $license_plate . "','" . $made_in_y . "','" . $made_in_m . "','" . $loop_tp . "','" . $cur_d . "','" . $befo_d . "','" . $driver_chg_dt . "');select @out_err_cd, @out_err_msg;";
		//echo $sql;
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}
}